<?php
/**
 * Yotaku shop - yshop
 * Copyright (c) 2016 http://www.yotaku.cn All rights reserved.
 * Author: Creatint <creatint@163.com> <http://creatint.yotaku.cn>
 */
namespace Admin\Controller;
use Think\Controller;

class ArticleController extends Controller{
    public function index(){
        $Article    =   D("Article");
        if($lists = $Article->getLists()){
            trace($lists,'lists');
            $this->assign('lists',$lists);
            $this->display();
        }else{
            $this->error($Article->getError());
        }
    }
    public function edit(){
        if($id = I("id")){
            $Article    =   D("Article");
            if($info = $Article->getDetail($id)){
                trace($info,'info');
                $this->assign('info',$info);
                $this->assign('pannel_title','文章编辑');
            }else{
                $this->error($Article->getError());
            }
        }else{
            $this->assign('pannel_title','添加文章');
        }
        $this->display();
    }

    public function update(){
        if(IS_POST){
            $Article    =   D("Article");
            $data = $_POST;
            trace($_POST,'post');
            if($res = $Article->update($data)){
                $this->success($data['id']?'修改成功':'增加成功');
            }else{
                //$this->error($Article->getError());
            }


        }
    }
    public function detail($id){
        $Article    =   D("Article");
        if($info = $Article->getDetail($id)){
            $this->assign('info',$info);
        }else{
            $this->error($Article->getError());
        }

    }
}